﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DiscoveryLogic.DataViz.NetworkDiagram.FieldComparers;
using DiscoveryLogic.DataViz.NetworkDiagram.NetworkData;

namespace DiscoveryLogic.DataViz.NetworkDiagram.Dedup
{
    /// <summary>
    /// 
    /// </summary>
    public class OrgDeduper:IDedupCalculator
    {
        #region Implementation of IDedupCalculator

        private Dictionary<string, IAttributeComparer> _NativeComparers;
        /// <summary></summary>
        public Dictionary<string, IAttributeComparer> NativeFieldComparers
        {
            get
            {
                return _NativeComparers;
            }
            set
            {
                _NativeComparers = value;
            }
        }

        private Dictionary<string, IAttributeComparer> _AssociativeComparers;
        /// <summary></summary>
        public Dictionary<string, IAttributeComparer> AssociativeFieldComparers
        {
            get
            {
                return _AssociativeComparers;
            }
            set
            {
                _AssociativeComparers = value;
            }
        }

        private Dictionary<string, double> _Weights;
        /// <summary></summary>
        public Dictionary<string, double> FieldWeights
        {
            get
            {
                return _Weights;
            }
            set
            {
                _Weights = value;
            }
        }

        private Dictionary<string, double> _Penalties;
        /// <summary></summary>
        public Dictionary<string, double> FieldPenalties
        {
            get
            {
                return _Penalties;
            }
            set
            {
                _Penalties = value;
            }
        }

        private double _AssociativeThreshold;
        /// <summary></summary>
        public double AssociativeScoreThreshold
        {
            get
            {
                return _AssociativeThreshold;
            }
            set
            {
                _AssociativeThreshold = value;
            }
        }

        private double _CollapseThreshold;
        /// <summary></summary>
        public double CollapseScoreThreshold
        {
            get
            {
                return _CollapseThreshold;
            }
            set
            {
                _CollapseThreshold = value;
            }
        }

        /// <summary></summary>
        public double? CalculateSimilarity(BaseEntity entity1, BaseEntity entity2)
        {
            if(entity1!=null && entity1 is ExternalOrgDO && 
                entity2 !=null && entity2 is ExternalOrgDO)
            {
                ExternalOrgDO org1 = (ExternalOrgDO) entity1;
                ExternalOrgDO org2 = (ExternalOrgDO) entity2;
                double similarity = 0;
                if(!string.IsNullOrEmpty(org1.OrgName) && !string.IsNullOrEmpty(org2.OrgName))
                {
                    similarity += 0.6;
                }

                return similarity;
            }

            return null;
        }

        #endregion
    }
}
